package cn.e3mall.test.solr.repository;

import cn.e3mall.test.solr.pojo.SearchItem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.solr.core.query.result.FacetPage;
import org.springframework.data.solr.core.query.result.HighlightPage;
import org.springframework.data.solr.repository.Facet;
import org.springframework.data.solr.repository.Highlight;
import org.springframework.data.solr.repository.Query;
import org.springframework.data.solr.repository.SolrCrudRepository;

import java.util.Collection;

public interface SearchItemRepository extends SolrCrudRepository<SearchItem,String> {
    
    
    @Highlight(prefix = "<b>", postfix = "</b>")
    @Query(
            // fields = { "item_title" },
            fields = { "*" },
            defaultOperator = org.springframework.data.solr.core.query.Query.Operator.AND)
    // @Query(fields = { "title" })
    HighlightPage<SearchItem> findByTitleContains(Collection<String> names, Pageable page);
    
    @Query(value = "*:*",defaultOperator = org.springframework.data.solr.core.query.Query.Operator.OR)
    // @Query(fields = {"*"})
    Page<SearchItem> findByCategoryNameContaining(String name,Pageable page);
    
    @Query(
            // value = "*:*",
            fields = {"item_category_name"},
            defaultOperator = org.springframework.data.solr.core.query.Query.Operator.OR)
    // @Query(fields = {"*"})
    Page<SearchItem> findByCategoryNameContaining(Collection<String> names ,Pageable page);
    
    // @Facet(fields = { "item_category_name" })
    // FacetPage<SearchItem> findByNameStartsWith(Collection<String> nameFragments, Pageable pagebale);
}
